1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module pango.PgLanguage; 26 27 private import glib.Str; 28 private import glib.c.functions; 29 private import gobject.ObjectG; 30 private import pango.c.functions; 31 public import pango.c.types; 32 33 34 /** 35 * The `PangoLanguage` structure is used to 36 * represent a language. 37 * 38 * `PangoLanguage` pointers can be efficiently 39 * copied and compared with each other. 40 */ 41 public class PgLanguage 42 { 43 /** the main Gtk struct */ 44 protected PangoLanguage* pangoLanguage; 45 protected bool ownedRef; 46 47 /** Get the main Gtk struct */ 48 public PangoLanguage* getPgLanguageStruct(bool transferOwnership = false) 49 { 50 if (transferOwnership) 51 ownedRef = false; 52 return pangoLanguage; 53 } 54 55 /** the main Gtk struct as a void* */ 56 protected void* getStruct() 57 { 58 return cast(void*)pangoLanguage; 59 } 60 61 /** 62 * Sets our main struct and passes it to the parent class. 63 */ 64 public this (PangoLanguage* pangoLanguage, bool ownedRef = false) 65 { 66 this.pangoLanguage = pangoLanguage; 67 this.ownedRef = ownedRef; 68 } 69 70 71 /** */ 72 public static GType getType() 73 { 74 return pango_language_get_type(); 75 } 76 77 /** 78 * Get a string that is representative of the characters needed to 79 * render a particular language. 80 * 81 * The sample text may be a pangram, but is not necessarily. It is chosen 82 * to be demonstrative of normal text in the language, as well as exposing 83 * font feature requirements unique to the language. It is suitable for use 84 * as sample text in a font selection dialog. 85 * 86 * If @language is %NULL, the default language as found by 87 * [func@Pango.Language.get_default] is used. 88 * 89 * If Pango does not have a sample string for @language, the classic 90 * "The quick brown fox..." is returned. This can be detected by 91 * comparing the returned pointer value to that returned for (non-existent) 92 * language code "xx". That is, compare to: 93 * 94 * ``` 95 * pango_language_get_sample_string (pango_language_from_string ("xx")) 96 * ``` 97 * 98 * Returns: the sample string 99 */ 100 public string getSampleString() 101 { 102 return Str.toString(pango_language_get_sample_string(pangoLanguage)); 103 } 104 105 /** 106 * Determines the scripts used to to write @language. 107 * 108 * If nothing is known about the language tag @language, 109 * or if @language is %NULL, then %NULL is returned. 110 * The list of scripts returned starts with the script that the 111 * language uses most and continues to the one it uses least. 112 * 113 * The value @num_script points at will be set to the number 114 * of scripts in the returned array (or zero if %NULL is returned). 115 * 116 * Most languages use only one script for writing, but there are 117 * some that use two (Latin and Cyrillic for example), and a few 118 * use three (Japanese for example). Applications should not make 119 * any assumptions on the maximum number of scripts returned 120 * though, except that it is positive if the return value is not 121 * %NULL, and it is a small number. 122 * 123 * The [method@Pango.Language.includes_script] function uses this 124 * function internally. 125 * 126 * Note: while the return value is declared as `PangoScript`, the 127 * returned values are from the `GUnicodeScript` enumeration, which 128 * may have more values. Callers need to handle unknown values. 129 * 130 * Returns: An array of `PangoScript` values, with the number of entries in 131 * the array stored in @num_scripts, or %NULL if Pango does not have 132 * any information about this particular language tag (also the case 133 * if @language is %NULL). 134 * 135 * Since: 1.22 136 */ 137 public PangoScript[] getScripts() 138 { 139 int numScripts; 140 141 auto __p = pango_language_get_scripts(pangoLanguage, &numScripts); 142 143 return __p[0 .. numScripts]; 144 } 145 146 /** 147 * Determines if @script is one of the scripts used to 148 * write @language. 149 * 150 * The returned value is conservative; if nothing is known about 151 * the language tag @language, %TRUE will be returned, since, as 152 * far as Pango knows, @script might be used to write @language. 153 * 154 * This routine is used in Pango's itemization process when 155 * determining if a supplied language tag is relevant to 156 * a particular section of text. It probably is not useful 157 * for applications in most circumstances. 158 * 159 * This function uses [method@Pango.Language.get_scripts] internally. 160 * 161 * Params: 162 * script = a `PangoScript` 163 * 164 * Returns: %TRUE if @script is one of the scripts used 165 * to write @language or if nothing is known about @language 166 * (including the case that @language is %NULL), %FALSE otherwise. 167 * 168 * Since: 1.4 169 */ 170 public bool includesScript(PangoScript script) 171 { 172 return pango_language_includes_script(pangoLanguage, script) != 0; 173 } 174 175 /** 176 * Checks if a language tag matches one of the elements in a list of 177 * language ranges. 178 * 179 * A language tag is considered to match a range in the list if the 180 * range is '*', the range is exactly the tag, or the range is a prefix 181 * of the tag, and the character after it in the tag is '-'. 182 * 183 * Params: 184 * rangeList = a list of language ranges, separated by ';', ':', 185 * ',', or space characters. 186 * Each element must either be '*', or a RFC 3066 language range 187 * canonicalized as by [func@Pango.Language.from_string] 188 * 189 * Returns: %TRUE if a match was found 190 */ 191 public bool matches(string rangeList) 192 { 193 return pango_language_matches(pangoLanguage, Str.toStringz(rangeList)) != 0; 194 } 195 196 /** 197 * Gets the RFC-3066 format string representing the given language tag. 198 * 199 * Returns (transfer none): a string representing the language tag 200 */ 201 public override string toString() 202 { 203 return Str.toString(pango_language_to_string(pangoLanguage)); 204 } 205 206 /** 207 * Convert a language tag to a `PangoLanguage`. 208 * 209 * The language tag must be in a RFC-3066 format. `PangoLanguage` pointers 210 * can be efficiently copied (copy the pointer) and compared with other 211 * language tags (compare the pointer.) 212 * 213 * This function first canonicalizes the string by converting it to 214 * lowercase, mapping '_' to '-', and stripping all characters other 215 * than letters and '-'. 216 * 217 * Use [func@Pango.Language.get_default] if you want to get the 218 * `PangoLanguage` for the current locale of the process. 219 * 220 * Params: 221 * language = a string representing a language tag 222 * 223 * Returns: a `PangoLanguage` 224 */ 225 public static PgLanguage fromString(string language) 226 { 227 auto __p = pango_language_from_string(Str.toStringz(language)); 228 229 if(__p is null) 230 { 231 return null; 232 } 233 234 return ObjectG.getDObject!(PgLanguage)(cast(PangoLanguage*) __p); 235 } 236 237 /** 238 * Returns the `PangoLanguage` for the current locale of the process. 239 * 240 * On Unix systems, this is the return value is derived from 241 * `setlocale (LC_CTYPE, NULL)`, and the user can 242 * affect this through the environment variables LC_ALL, LC_CTYPE or 243 * LANG (checked in that order). The locale string typically is in 244 * the form lang_COUNTRY, where lang is an ISO-639 language code, and 245 * COUNTRY is an ISO-3166 country code. For instance, sv_FI for 246 * Swedish as written in Finland or pt_BR for Portuguese as written in 247 * Brazil. 248 * 249 * On Windows, the C library does not use any such environment 250 * variables, and setting them won't affect the behavior of functions 251 * like ctime(). The user sets the locale through the Regional Options 252 * in the Control Panel. The C library (in the setlocale() function) 253 * does not use country and language codes, but country and language 254 * names spelled out in English. 255 * However, this function does check the above environment 256 * variables, and does return a Unix-style locale string based on 257 * either said environment variables or the thread's current locale. 258 * 259 * Your application should call `setlocale(LC_ALL, "")` for the user 260 * settings to take effect. GTK does this in its initialization 261 * functions automatically (by calling gtk_set_locale()). 262 * See the setlocale() manpage for more details. 263 * 264 * Note that the default language can change over the life of an application. 265 * 266 * Also note that this function will not do the right thing if you 267 * use per-thread locales with uselocale(). In that case, you should 268 * just call pango_language_from_string() yourself. 269 * 270 * Returns: the default language as a `PangoLanguage` 271 * 272 * Since: 1.16 273 */ 274 public static PgLanguage getDefault() 275 { 276 auto __p = pango_language_get_default(); 277 278 if(__p is null) 279 { 280 return null; 281 } 282 283 return ObjectG.getDObject!(PgLanguage)(cast(PangoLanguage*) __p); 284 } 285 286 /** 287 * Returns the list of languages that the user prefers. 288 * 289 * The list is specified by the `PANGO_LANGUAGE` or `LANGUAGE` 290 * environment variables, in order of preference. Note that this 291 * list does not necessarily include the language returned by 292 * [func@Pango.Language.get_default]. 293 * 294 * When choosing language-specific resources, such as the sample 295 * text returned by [method@Pango.Language.get_sample_string], 296 * you should first try the default language, followed by the 297 * languages returned by this function. 298 * 299 * Returns: a %NULL-terminated array 300 * of `PangoLanguage`* 301 * 302 * Since: 1.48 303 */ 304 public static PgLanguage getPreferred() 305 { 306 auto __p = pango_language_get_preferred(); 307 308 if(__p is null) 309 { 310 return null; 311 } 312 313 return ObjectG.getDObject!(PgLanguage)(cast(PangoLanguage*) __p); 314 } 315 }